package dao;


import model.User;
import exception.BlogDaoException;

public class UserDao extends HibernateDao {
	/**
	 * 添加用户
	 * @param user
	 */
	public void saveUser(User user){
		if(user==null){
			return ;
		}
		User u=getUser(user.getUsername());
		if(u!=null){
			throw new BlogDaoException("用户已经存在");
		}
		System.out.println("开始存储");
		saveObject(user);
	}
	/**
	 * 
	 * @param name
	 * @return
	 */
	private User getUser(String username) {
		User u=(User) getObject("from User as u where u.username='"+username+"'");
		return u;
	}
	
	public User getUserById(String id){
		return getObject(User.class,id);
	}
}
